/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.edu.unicen.twitter.suggest.commons.tools;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 *
 * @author Alex
 */
public class CollectionsOperations {

    public static long[] getIdArray(Collection<Long> set) {

        if (set != null) {
            long[] array = new long[set.size()];
            int f = 0;
            for (Long id : set) {
                array[f] = id.longValue();
                ++f;
            }
            return array;
        } else {
            return new long[0];
        }
    }

    public static long[] getIdArray(int[] idShort) {

        if (idShort != null) {
            long[] array = new long[idShort.length];
            for (int i = 0; 0 < idShort.length; ++i) {
                array[i] = idShort[i];
            }
            return array;
        } else {
            return new long[0];
        }
    }

    public static int[] getIdShortArray(Collection<Integer> set) {

        if (set != null) {
            int[] array = new int[set.size()];
            int f = 0;
            for (Integer id : set) {
                array[f] = id.intValue();
                ++f;
            }
            return array;
        } else {
            return new int[0];
        }
    }

    public static Set<Integer> getSet(int[] array) {
        Set<Integer> set = new HashSet<Integer>();
        if (array != null) {
            for (int i = 0; i < array.length; ++i) {
                set.add(array[i]);
            }
        }
        return set;
    }
     public static List<Long> getList(int[] array) {
        List<Long> set = new ArrayList<Long>();
        if (array != null) {
            for (int i = 0; i < array.length; ++i) {
                set.add((long)array[i]);
            }
        }
        return set;
    }
     public static List<Long> getList(long[] array) {
        List<Long> set = new ArrayList<Long>();
        if (array != null) {
            for (int i = 0; i < array.length; ++i) {
                set.add(array[i]);
            }
        }
        return set;
    }
     public static List<Long> getListIntersection(int[] array1, int[] array2){
        Set<Long> set = new HashSet<Long>();
        if (array1 != null) {
            for (int i = 0; i < array1.length; ++i) {
                set.add((long)array1[i]);
            }
        }
        List<Long> list = new ArrayList<Long>();
        if (array2 != null) {
            for (int i = 0; i < array2.length; ++i) {
                if(set.contains((long)array2[i])){
                    list.add((long)array2[i]);
                }
            }
        }
        return list;
     }
}
